package com.czx.recyclerview;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;



public class GridRVitemDecoration extends RecyclerView.ItemDecoration {

    private Paint mPaint = new Paint();

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        mPaint.setColor(Color.BLACK);
        int childCount = parent.getChildCount();
        for(int i = 0;i<childCount;i++){
            if(i == 0){
                continue;
            }
            View childView = parent.getChildAt(i);
            int width = childView.getWidth();
            int height = childView.getHeight();
            float x = childView.getX();
            float y = childView.getY();

            c.drawLine(x,y,x+width,y,mPaint);
            c.drawLine(x,y+height,x+width,y+height,mPaint);
            c.drawLine(x,y,x,y+height,mPaint);
            c.drawLine(x+width,y,x+width,y+height,mPaint);
        }
        super.onDraw(c, parent, state);
    }
}
